<!--  -->
<template>
        <div>
          <div v-if="requestError" class="text-c errorPlace">
            <img width="100px" height="100px" :src="require('@/assets/images/pic_neterror.png')" alt="获取数据失败" />
            <div class="color-b font14" style="margin: 10px 0 0 0">
              获取数据失败!
            </div>
            <van-button plain round size="small" color="#7232dd" type="primary" @click="getdetail">点击重试</van-button>
          </div>
         <van-form @submit="submitFromData">

           <div class="mt10" style=" display: flex;border-bottom: 1px solid #ebedf0;">
             <div class="blue_item" />
             <span class="font15" style="display: flex; line-height: 33px;margin-left:5px;  flex:1;">提交报名提示：该表单带*字段都为必填项</span>
           </div>
           <van-field readonly required name="isExist" :value="fromdata.isExist" label="是否在合作伙伴库：" label-width="9em" />
           <van-field readonly required name="partnerCode" :value="fromdata.partnerCode" label="合作伙伴编码：" label-width="7em" />
           <van-field readonly required name="partnerName" :value="fromdata.partnerName" label="合作伙伴名称：" label-width="8em" />
           <van-field readonly name="partnerAddress" :value="fromdata.partnerAddress" label="合作伙伴注册地址：" label-width="9em" />
           <van-field readonly name="partnerEmpNum" :value="fromdata.partnerEmpNum" label="合作伙伴规模(人数)：" label-width="10.5em" />
           <van-field readonly name="partnerDays" :value="fromdata.partnerDays" label="合作伙伴成立天数：" label-width="9em" />
           <van-field readonly name="isUpDownAssociation" :value="fromdata.isUpDownAssociation" label="上下游是否存在关联关系：" label-width="12em" />
           <van-field readonly name="dictRelType" :value="fromdata.dictRelType" label="企业关联类型：" label-width="7em" />
           <van-field readonly name="associationPath" :value="fromdata.associationPath" label="关联路径：" label-width="5em" />
           <van-field readonly required name="contact" :value="fromdata.contact" label="联系人：" label-width="5em" />
           <van-field readonly required name="contactPhone" :value="fromdata.contactPhone" label="联系电话：" label-width="6em" />
           <van-field readonly required name="pickIndustry" :value="fromdata.pickIndustry" label="甄选行业：" label-width="5em" />
           <van-field readonly required name="pickScene" :value="fromdata.pickScene" label="甄选场景：" label-width="5em" />
           <van-field readonly required name="contactEmail" :value="fromdata.contactEmail" label="联系人邮箱：" label-width="6em" />
           <van-field readonly required name="applyPlanCode" :value="fromdata.applyPlanCode" label="应征方案编码：" label-width="7em" />

           <van-field readonly required label="合作伙伴应征方案:" label-width="9em" />
           <div v-for="(fileitem) in fromdata.partnerApplyPlanList" :key="fileitem.id" style="margin-left:20px">
             <div readonly class="font14 fileLink" style="color:#0F85CF">
               <a target="_blank" @click="openFileUrlfun(fileitem.anonymousFilePath)">{{ fileitem.fileName }}</a>
             </div>
           </div>
           <van-field v-if="fromdata.password" readonly name="password" :value="fromdata.password" label="应征方案解压密码：" label-width="9em" />
           <div class="footer" v-if="isYiBan==false">
             <van-button block type="info" native-type="submit" :disabled="canNextInMobile?false:true"
                         style="display: inline-block;width:100%;border: 0px solid #60a9ec;">{{ sumitBottonText }}</van-button>
           </div>
         </van-form>
         <historyAndSuggs :showHistory='isYiBan' :historydata='historydata' :approveList='approveList' />
      </div>
</template>

<script>
import {getSrqrRequest, getWfOptMags, wfWorkItemModel} from '@/api/dictapi'
import {mapGetters} from "vuex"
import { Notify, Toast } from 'vant'
import util from "@/assets/js/public";
import {openFileUrl} from '@/store/openFile';
import historyAndSuggs from "@/views/srqr/historyAndSuggs.vue"
  export default {
    components: {historyAndSuggs},
    data() {
      return {
        fromdata:{},//表单数据
        requestError: false,
        canNextInMobile: true,//当前环节是否可在手机端办理
        isYiBan: false,
        historydata: {},//已办显示当前办理人
        approveList: [],//审批意见列表
        params:this.$route.query
      }
    },
    computed:{
        ...mapGetters(['user']),
        ...mapGetters(['userinfo']),
        sumitBottonText: function () {
          if (this.canNextInMobile) {
            return "流转下一步";
          } else {
            return "暂不支持该环节,请至PC端办理";
          }
        },
    },
    //生命周期--创建完成
    activated() {
      this.params=this.$route.query
      Object.assign(this.params, { userName: this.user.userName })
      if (this.params.todoType % 2 == 0) {
        this.isYiBan = true;
      }
      if (this.params.location == 'dict.start') {
        this.canNextInMobile = false;
      }
      if(!this.fromdata||Object.keys(this.fromdata).length === 0){
        this.getdetail();
      }
    },
    //方法调用
    methods: {
          openFileUrlfun(value) {
            this.$router.push({
              name: "fileview",
              query: {
                openFileUrl: openFileUrl(value),
              },
            });
          },
        getdetail(){
          Toast.loading({
              message:'加载中',
              forbidClick:false
          });
          getSrqrRequest("pickPartnerAnswer$api$findByPmInsId",{
            kv: {
              "source": 'MOBILE',
              "pmInsId":this.params.pmInsId,
              "currentUserCode": util.encrypt(this.user.userName),
            }
          }).then((result)=>{
                  this.requestError=false;
                  Toast.clear();
                  if(!result.data){
                      Notify(result.message);
                      return;
                  }
                  if(result.data.data){
                    this.fromdata=result.data.data;
                  }
                  if (this.isYiBan) {
                    this.wfWorkItemModel();
                  }
                  this.getWfOptMags();
              })
          .catch(() => {
            this.requestError=true;
            Toast.clear();
          });
        },
      wfWorkItemModel() {
        wfWorkItemModel(this.params)
            .then((result) => {
              if (!result.data) {
                Notify(result.message);
                return;
              }
              if (result.data.data) {
                this.historydata = result.data.data
                this.historydata.MANAGER = this.historydata.participantName || '暂无';
                this.historydata.DEPARTMENT = this.historydata.workItemName || '暂无';
              }
            })
      },
      //获取审批意见
      getWfOptMags() {
        getWfOptMags(this.params)
            .then((result) => {
              if (!result.data) {
                Notify(result.message);
                return;
              }
              this.approveList = result.data.data.reverse();
            })
      },
      submitFromData(){
        this.params.formData=this.fromdata;
        var formSendData={"htmlParamMap":{}};
        formSendData.htmlParamMap = this.fromdata;
        formSendData.htmlParamMap.incomeList=this.fromdata.incomeListModel
        formSendData.htmlParamMap.incomeListModel=null
        formSendData.id = this.fromdata.id;
        formSendData.pmInsId = this.params.pmInsId;
        formSendData.processType = this.params.pmInsType;
        formSendData.workItemId = this.params.workItemId;
        console.log("传给递交页面:", this.params)
        var params1 = {
          kv: {
            currentUserCode: util.encrypt(this.params.userName),
            source: 'MOBILE',
            location: this.params.location,
            processInstId: this.params.processInstId,
            processDefName: this.params.processDefName,
            processType: this.params.pmInsType,
          },
        };
        var params2 = {
          kv: {
            "currentUserCode": util.encrypt(this.params.userName),
            "source": 'MOBILE',
            "location": this.params.location,
            "processInstId": this.params.processInstId,
            'processType': this.params.pmInsType,
            'receiptCode': this.params.processInstId
          },
        };
        var params3 = {
          kv: {
            "source": 'MOBILE',
            "currentUserCode": util.encrypt(this.params.userName),
            "workItemId": this.params.todoType==3?"":this.params.workItemId,
            "processInstId": this.params.processInstId,
            "location": this.params.location,
            "notificationId":this.params.todoType==3?this.params.wfnid:""
          },
        };
        localStorage.setItem('submitPageParam', JSON.stringify({
          getDecisionsUrl:'decisionAndUser$api$getDecisions',
          getDecisionsParams:params1,
          getUserUrl:'decisionAndUser$api$getOrgAndUser',
          getUserParams:params2,
          tosubmintUrl:'applicationFormEnhance$api$startSubmitProcess',
          tosubmintParams:params3,
          formData:formSendData,
          fromMoa:this.params.fromMoa,
          type:this.params.todoType==3?"toRead":"toDo"
        }));
        this.$router.push({
              name: 'srqrsubmit'
            }
        );
       }
    }
  }
</script>
<style  scoped>
/* @import url();*/
</style>